package com.union.core.sys.action;

import java.util.List;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;
import com.union.core.sys.model.SysLogs;
import com.union.core.sys.service.SysLogsService;
import com.union.core.sys.service.SysService;

public class SysLogsAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 3293528899673363810L;
	private SysService sysService = SysService.getInstance();
	//分页设置
	private int page=1;			//页码
	private int intRowCount;	//总行数
	private int intPageCount;	//总页数
	private int start;				//开始
	private int intPageSize=15;	//每页显示的行数
	private int intPage;		//页数变量
	//日志
	private int GUID;
	private String date;
	private String messages;
	private String operaPerson;
	private String operaOrgenization;
	private String operaAccount;
	private String ParamName;
	private String ParamValue;
	private String orderBy;
	private SysLogsService sysLogsService;
	private List<SysLogs> logsList;
	//日期参数
	private String startDate;
	private String endDate;
	
	public SysLogsAction(){
		sysLogsService=new SysLogsService();
	}
	public String logsIndex(){
		if(sysService.ifTimeOut()==false){
			return "TIMEOUT";//超时
		}else{
			lookLogs();
			setQuerySession();
		}
		return SUCCESS;
	}
	public String pagelist(){
		if(sysService.ifTimeOut()==false){
			return "TIMEOUT";//超时
		}else{
			getQuerySession();
			lookLogs();
		}
		return SUCCESS;
	}
	private void lookLogs(){
		
		if("".equals(GUID))GUID = 0;
		if("".equals(date))date = null;
		if("".equals(messages))messages = null;
		if("".equals(startDate))startDate = null;
		if("".equals(endDate))endDate = null;
		if("".equals(operaPerson))operaPerson = null;
		if("".equals(operaOrgenization))operaOrgenization = null;
		if("".equals(operaAccount))operaAccount = null;
		
		if("".equals(ParamName))ParamName = null;
		if("".equals(ParamValue))ParamValue = null;
		if("".equals(orderBy))orderBy = null;
		
		if(page<1){
			intPage = 1;
			page=1;
		}else{
			intPage = page;
		}
		intRowCount  = sysLogsService.querySysLogsCount(GUID,date, messages, operaPerson, operaOrgenization, 
				operaAccount,startDate,endDate, ParamName, ParamValue);
		intPageCount = (intRowCount + intPageSize - 1) / intPageSize;
		if(intPage > intPageCount) intPage = intPageCount;		
		if(intPageCount>0){
			start = (intPage-1) * intPageSize;
			logsList=sysLogsService.querySysLogs(GUID,date, messages, operaPerson, 
					operaOrgenization, operaAccount,startDate,endDate, ParamName, ParamValue, orderBy, start, intPageSize);
		}
	}

	private void setQuerySession(){
		ServletActionContext.getRequest().getSession().setAttribute("GUID",GUID); 
		ServletActionContext.getRequest().getSession().setAttribute("messages",messages); 
		ServletActionContext.getRequest().getSession().setAttribute("operaPerson",operaPerson); 
		ServletActionContext.getRequest().getSession().setAttribute("operaAccount",operaAccount);  
		ServletActionContext.getRequest().getSession().setAttribute("startDate",startDate); 
		ServletActionContext.getRequest().getSession().setAttribute("endDate",endDate); 
		ServletActionContext.getRequest().getSession().setAttribute("ParamName",ParamName); 
		ServletActionContext.getRequest().getSession().setAttribute("ParamValue",ParamValue); 
		ServletActionContext.getRequest().getSession().setAttribute("orderBy",orderBy); 
	}
	
	private void getQuerySession(){
		GUID = (Integer)ServletActionContext.getRequest().getSession().getAttribute("GUID");
		messages = (String)ServletActionContext.getRequest().getSession().getAttribute("messages");
		operaPerson = (String)ServletActionContext.getRequest().getSession().getAttribute("operaPerson");
		operaAccount = (String)ServletActionContext.getRequest().getSession().getAttribute("operaAccount");
		startDate = (String)ServletActionContext.getRequest().getSession().getAttribute("startDate");
		endDate = (String)ServletActionContext.getRequest().getSession().getAttribute("endDate");
		ParamName = (String)ServletActionContext.getRequest().getSession().getAttribute("ParamName");
		ParamValue = (String)ServletActionContext.getRequest().getSession().getAttribute("ParamValue");
		orderBy = (String)ServletActionContext.getRequest().getSession().getAttribute("orderBy");
	}
	public int getPage() {
		return page;
	}
	public void setPage(int page) {
		this.page = page;
	}
	public int getIntRowCount() {
		return intRowCount;
	}
	public void setIntRowCount(int intRowCount) {
		this.intRowCount = intRowCount;
	}
	public int getIntPageCount() {
		return intPageCount;
	}
	public void setIntPageCount(int intPageCount) {
		this.intPageCount = intPageCount;
	}
	public String getDate() {
		return date;
	}
	public void setDate(String date) {
		this.date = date;
	}
	public String getMessages() {
		return messages;
	}
	public void setMessages(String messages) {
		this.messages = messages;
	}
	public String getOperaPerson() {
		return operaPerson;
	}
	public void setOperaPerson(String operaPerson) {
		this.operaPerson = operaPerson;
	}
	public String getOperaOrgenization() {
		return operaOrgenization;
	}
	public void setOperaOrgenization(String operaOrgenization) {
		this.operaOrgenization = operaOrgenization;
	}
	public String getOperaAccount() {
		return operaAccount;
	}
	public void setOperaAccount(String operaAccount) {
		this.operaAccount = operaAccount;
	}
	public String getParamName() {
		return ParamName;
	}
	public void setParamName(String paramName) {
		ParamName = paramName;
	}
	public String getParamValue() {
		return ParamValue;
	}
	public void setParamValue(String paramValue) {
		ParamValue = paramValue;
	}
	public String getOrderBy() {
		return orderBy;
	}
	public void setOrderBy(String orderBy) {
		this.orderBy = orderBy;
	}
	public List<SysLogs> getLogsList() {
		return logsList;
	}
	public void setLogsList(List<SysLogs> logsList) {
		this.logsList = logsList;
	}
	public String getStartDate() {
		return startDate;
	}
	public void setStartDate(String startDate) {
		this.startDate = startDate;
	}
	public String getEndDate() {
		return endDate;
	}
	public void setEndDate(String endDate) {
		this.endDate = endDate;
	}
	public int getStart() {
		return start;
	}
	public void setStart(int start) {
		this.start = start;
	}
	public int getIntPageSize() {
		return intPageSize;
	}
	public void setIntPageSize(int intPageSize) {
		this.intPageSize = intPageSize;
	}
	public int getIntPage() {
		return intPage;
	}
	public void setIntPage(int intPage) {
		this.intPage = intPage;
	}
	public int getGUID() {
		return GUID;
	}
	public void setGUID(int gUID) {
		GUID = gUID;
	}
}
